const path = require('path')

const rulesConfig = require('./webpack.rules.js')
const pluginsConfig = require('./webpack.plugins.js')
const webpack = require('webpack')

const isDev = process.env.NODE_ENV === 'development'

const config = {
	target: 'web',
	entry: path.join(__dirname,'src/index.js'),
	output: {
		filename: 'main.js',
		path: path.join(__dirname,'dist')
	},
	module:{
		rules: rulesConfig
	},
	plugins: pluginsConfig
}

if(isDev){
	config.devtool = '#cheap-module-eval-source-map'//在浏览器调试.vue es6代码
	config.devServer = {
		port: 8000,
		host: '0.0.0.0',//通过localhost ，ip ，手机页上也能访问
		overlay: {
			errors: true,//错误显示到网页上
		},
		hot: true//需要插件
	}
	config.plugins.push(
		//允许创建一个在编译时可以配置的全局常量。js代码中也可使用
		new webpack.DefinePlugin({
			'process.env': {
				NODE_ENV: isDev ? '"development"' : '"production"'
			}
		}),
		//模块热替换插件
		new webpack.HotModuleReplacementPlugin(),
		// new webpack.NoEmitOnErrorsPlugin()

	)
}

module.exports = config
